package com.ljfiction.book.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ljfiction.book.Baner.ShouCangBookBean;
import com.ljfiction.book.MyView.SuperButton;
import com.ljfiction.book.R;
import com.ljfiction.book.fragment.BookshelfFragment;
import com.ljfiction.book.tools.ScreenUtils;
import com.ljfiction.book.tools.TimeTool;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.List;

/**
 * Created by Android on 2017/10/18.
 */

public class ShouCangBookAdapter extends BaseQuickAdapter<ShouCangBookBean.DataBean.ListBean, BaseViewHolder> {
    public ShouCangBookAdapter(@LayoutRes int layoutResId, @Nullable List<ShouCangBookBean.DataBean.ListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, ShouCangBookBean.DataBean.ListBean item) {
        AutoUtils.autoSize(helper.itemView);
        if (helper.getLayoutPosition() ==mData.size()-1) {
            Glide.with(mContext).load(R.drawable.addbook).override(ScreenUtils.getNum(mContext,109),ScreenUtils.getNum(mContext,145)).into((ImageView) helper.getView(R.id.shujiabookimage));
            helper.getView(R.id.isselect).setVisibility(View.GONE);
            helper.getView(R.id.iswanjie).setVisibility(View.GONE);
        } else {
            helper.getView(R.id.iswanjie).setVisibility(View.VISIBLE);
            Glide.with(mContext).load(item.getBookImage()).override(ScreenUtils.getNum(mContext,109),ScreenUtils.getNum(mContext,145)).into((ImageView) helper.getView(R.id.shujiabookimage));
            helper.setText(R.id.shujiabookname, item.getBookName())
                    .setText(R.id.shujiabookgettime, TimeTool.getDateTime(item.getLastUpdateTime()));

            if ("1".equals(item.getBookCheckStatus())) {
                ((SuperButton)helper.getView(R.id.iswanjie)).setsSolidColor("#FB5E6F");
                ((SuperButton) helper.getView(R.id.iswanjie)).setText("完结");
            } else {
                ((SuperButton)helper.getView(R.id.iswanjie)).setsSolidColor("#6EC282");
                ((SuperButton) helper.getView(R.id.iswanjie)).setText("更新");
            }
            if(BookshelfFragment.isbianji){
                helper.getView(R.id.isselect).setVisibility(View.VISIBLE);
                if (item.isSelect()){
                    ((ImageView) helper.getView(R.id.isselect)).setImageResource(R.mipmap.done);
                }else {
                    ((ImageView) helper.getView(R.id.isselect)).setImageResource(R.mipmap.none);
                }
            }else {
                helper.getView(R.id.isselect).setVisibility(View.GONE);
            }

        }
    }
}
